#include "pickteams.h"
#include "ui_pickteams.h"


PickTeams::PickTeams(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PickTeams)
{
    ui->setupUi(this);
    getTeams();
    populateHome();
    populateAway();

}

PickTeams::~PickTeams()
{
    delete ui;
}

void PickTeams::ShowScoreKeeper() {

    int home_index = ui->comboBox->currentIndex();
    int away_index = ui->comboBox_3->currentIndex();

    sckeep = new Lineups();
    sckeep->setHome(all_teams[home_index]);
    sckeep->setAway(all_teams[away_index]);
    sckeep->prepareWindow();

}

void PickTeams::getTeams() {


       QSqlQuery query;
       query.prepare("Select * from teams");
       query.exec();

       while(query.next()) {
           Team *temp_team = new Team();
           temp_team->setName(query.value(0).toString());
           temp_team->setId(query.value(1).toInt());
           all_teams.append(temp_team);
      }
       query.finish();


}

void PickTeams::populateHome() {

   foreach(Team *each_team, all_teams) {
       ui->comboBox->addItem(each_team->getName(), QVariant(each_team->getID()));
         }

}

void PickTeams::populateAway() {

   foreach(Team *each_team, all_teams) {
       ui->comboBox_3->addItem(each_team->getName(), QVariant(each_team->getID()));
         }

}
